package com.ruoyi.annuity.controller;

import com.ruoyi.annuity.domain.TbAnnuityRecord;
import com.ruoyi.annuity.service.ITbAnnuityRecordService;
import com.ruoyi.annuity.utils.SnowFlake;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 年费信息Controller
 * 
 * @author ruoyi
 * @date 2023-04-24
 */
@RestController
@RequestMapping("/annuity")
public class TbAnnuityRecordController extends BaseController
{
    @Autowired
    private ITbAnnuityRecordService tbAnnuityRecordService;

    @Autowired
    private SnowFlake snowFlake;

    /**
     * 查询年费信息列表
     */
    @RequiresPermissions("annuity:annuity:list")
    @GetMapping("/list")
    public TableDataInfo list(TbAnnuityRecord tbAnnuityRecord)
    {
        startPage();
        List<TbAnnuityRecord> list = tbAnnuityRecordService.selectTbAnnuityRecordList(tbAnnuityRecord);
        return getDataTable(list);
    }

    /**
     * 导出年费信息列表
     */
    @RequiresPermissions("annuity:annuity:export")
    @Log(title = "年费信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAnnuityRecord tbAnnuityRecord)
    {
        List<TbAnnuityRecord> list = tbAnnuityRecordService.selectTbAnnuityRecordList(tbAnnuityRecord);
        ExcelUtil<TbAnnuityRecord> util = new ExcelUtil<TbAnnuityRecord>(TbAnnuityRecord.class);
        util.exportExcel(response, list, "年费信息数据");
    }

    /**
     * 获取年费信息详细信息
     */
    @RequiresPermissions("annuity:annuity:query")
    @GetMapping(value = "/{annuityRecordId}")
    public AjaxResult getInfo(@PathVariable("annuityRecordId") Long annuityRecordId)
    {
        return success(tbAnnuityRecordService.selectTbAnnuityRecordByAnnuityRecordId(annuityRecordId));
    }

    /**
     * 新增年费信息
     */
    @RequiresPermissions("annuity:annuity:add")
    @Log(title = "年费信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAnnuityRecord tbAnnuityRecord)
    {
        tbAnnuityRecord.setAnnuityRecordId(SnowFlake.nextId());
        tbAnnuityRecord.setStatus(1);
        return toAjax(tbAnnuityRecordService.insertTbAnnuityRecord(tbAnnuityRecord));
    }

    /**
     * 修改年费信息
     */
    @RequiresPermissions("annuity:annuity:edit")
    @Log(title = "年费信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAnnuityRecord tbAnnuityRecord)
    {
        return toAjax(tbAnnuityRecordService.updateTbAnnuityRecord(tbAnnuityRecord));
    }

    /**
     * 删除年费信息
     */
    @RequiresPermissions("annuity:annuity:remove")
    @Log(title = "年费信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{annuityRecordIds}")
    public AjaxResult remove(@PathVariable Long[] annuityRecordIds)
    {
        return toAjax(tbAnnuityRecordService.deleteTbAnnuityRecordByAnnuityRecordIds(annuityRecordIds));
    }
}
